Page({

  data: {
    tabs: ['热门技术', '秒杀时刻', '畅销书籍'],
    currentTab: 0,
    books: []
  },
  onLoad(options: WechatMiniprogram.Page.DataOption) {
    const currentTab = options.id
    this.setData({ currentTab })
    this.refreshData()
  },
  onTab(e: WechatMiniprogram.ControlTap) {
    const { id } = e.currentTarget.dataset
    this.setData({
      currentTab: id
    })
    this.refreshData()
  },
  refreshData() {
    wx.showLoading({ title: '正在加载' })
    wx.request({
      url: `${getApp<IAppOption>().globalData.baseURL}getGoodsListByType?type=${this.data.currentTab}`,
      success: ({ data }) => {
        //@ts-ignore
        const books = data.data;
        this.setData({
          books
        })
        wx.hideLoading()
      }
    })
  },
  gotoSearch() {
    wx.navigateTo({
      url: '../search/search',
    })
  },
})